import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../../resource/language/generated/l10n.dart';
import '../../interface/root_proxy_model.dart';
import '../mic_seat/mic_seat_scene.dart';
import '../mic_seat/mic_seat_widget.dart';
import 'mic_resource_setting_page_model.dart';

///
/// 排麦列表
///
class MicResourceSettingPage extends StatefulWidget {
  const MicResourceSettingPage({super.key});

  @override
  State<MicResourceSettingPage> createState() => _MicResourceSettingPageState();
}

class _MicResourceSettingPageState extends State<MicResourceSettingPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProxyProvider<RootProxyModel,
            MicResourceSettingPageModel>(
          create: (context) => MicResourceSettingPageModel(),
          update: (context, rootProxyModel, leafModel) {
            if (leafModel == null) throw ArgumentError.notNull('leafModel');
            leafModel.roomModel = rootProxyModel;
            return leafModel;
          },
        ),
      ],
      child: Consumer<MicResourceSettingPageModel>(
          builder: (context, model, child) {
        return _buildContent(context, model);
      }),
    );
  }

  Widget _buildContent(
      BuildContext context, MicResourceSettingPageModel model) {
    return Container(
      width: double.infinity,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(16),
        color: Colors.white,
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const SizedBox(
            height: 20,
          ),
          Align(
            alignment: Alignment.topCenter,
            child: Text(
              T.current.seat_frame_setting,
              style: const TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w600,
                color: Color(0xff333333),
              ),
            ),
          ),
          const SizedBox(
            height: 20,
          ),
          Container(
            padding: const EdgeInsets.only(top: 30),
            width: double.infinity,
            child: MicSeatWidget(
              micSeatScene: MicSeatScene.SEAT_FRAME_SETTING,
            ),
          ),
          const SizedBox(
            height: 20,
          ),
          Row(
            children: [
              const SizedBox(
                width: 40,
              ),
              Expanded(
                  child: CupertinoButton(
                      minSize: 0,
                      padding: EdgeInsets.zero,
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color(0xFFF6F7F9),
                          borderRadius: BorderRadius.circular(24),
                        ),
                        width: double.infinity,
                        height: 52,
                        alignment: Alignment.center,
                        child: Text(
                          T.current.clear,
                          style: const TextStyle(
                            color: Color(0xff666666),
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      onPressed: () async {
                        model.clear();
                      })),
              const SizedBox(
                width: 15,
              ),
              Expanded(
                  child: CupertinoButton(
                      minSize: 0,
                      padding: EdgeInsets.zero,
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color(0xFFFFD400),
                          borderRadius: BorderRadius.circular(24),
                        ),
                        width: double.infinity,
                        height: 52,
                        alignment: Alignment.center,
                        child: Text(
                          T.current.surer,
                          style: const TextStyle(
                            color: Color(0xff333333),
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      onPressed: () async {
                        model.confirm(context);
                      })),
              const SizedBox(
                width: 40,
              ),
            ],
          ),
          const SafeArea(
              child: SizedBox(
            height: 30,
          )),
        ],
      ),
    );
  }
}
